/*
 * generate by table-builder.Don't modify it
 */
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using System.Collections.Generic;


namespace CfgTable
{
    public partial class TbCfgPhysicalEntity
    {
        private readonly Dictionary<int, CfgPhysicalEntity> _dataMap;
        private readonly List<CfgPhysicalEntity> _dataList;


        public TbCfgPhysicalEntity(ByteBuf _buf)
        {
            //first read common data
            _TbCommonPhysicalEntity _commonData = null;
            var commonSize = _buf.ReadSize();
            if (commonSize > 0)
            {
                _commonData = new _TbCommonPhysicalEntity(_buf);
            }

            //then read row data
            var size = _buf.ReadSize();
            _dataMap = new Dictionary<int, CfgPhysicalEntity>(size * 3 / 2);
            _dataList = new List<CfgPhysicalEntity>(size);

            for (int i = 0; i < size; i++)
            {
                CfgPhysicalEntity _v;
                _v = CfgPhysicalEntity.DeserializeCfgPhysicalEntity(_buf, _commonData);
                _dataList.Add(_v);
                _dataMap.Add(_v.Id, _v);
            }

            // read extra fields 

            PostInit();
        }

        public IReadOnlyDictionary<int, CfgPhysicalEntity> DataMap => _dataMap;
        public IReadOnlyList<CfgPhysicalEntity> DataList => _dataList;

        public CfgPhysicalEntity Get(int key)
        {
            if (_dataMap.TryGetValue(key, out var v))
            {
                return v;
            }
            IQIGame.Onigao.Framework.LogGame.LogError("[TbCfgPhysicalEntity] config not found,id:" + key.ToString());

            return null;
        }

        public CfgPhysicalEntity GetWithoutError(int key) => _dataMap.TryGetValue(key, out var v) ? v : null;

        /// <summary>
        /// table data file
        /// </summary>
        public static string TableFileName { get; } = "physicalentity";

        /// <summary>
        /// load table function
        /// </summary>
        public static TbCfgPhysicalEntity LoadFromFunc(System.Func<string, ByteBuf> loadFunc)
        {
            return new TbCfgPhysicalEntity(loadFunc(TableFileName));
        }

        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();

    }

    public partial class CfgPhysicalEntity
    {
        private CfgPhysicalEntity(ByteBuf _buf, _TbCommonPhysicalEntity _commonData)
        {
            Id = _buf.ReadInt();
            EntityType = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; EntityAsset = _commonData._field0[dataIndex]; }
            DieDuration = _buf.ReadInt();
            InteractExtendedRange = _buf.ReadInt();
            DefaultSpeed = _buf.ReadInt();
            RotationTime = _buf.ReadInt();
            { int dataIndex = _buf.ReadInt() - 1; DefaultAudioSheet = _commonData._field1[dataIndex]; }
            ActivateWallActionPlay = _buf.ReadBool();
            NoInteractiveIcon = _buf.ReadBool();
            ViewTriggerAction = _buf.ReadInt();
            HitSound = _buf.ReadInt();

            PostInit();
        }

        internal static CfgPhysicalEntity DeserializeCfgPhysicalEntity(ByteBuf _buf, _TbCommonPhysicalEntity _commonData)
        {
            return new CfgPhysicalEntity(_buf, _commonData);
        }

        /// <summary>
        /// major key
        /// </summary>
        public int Id { get; private set; }

        /// <summary>
        /// 元素类型（0:主角|1:关卡模型）
        /// </summary>
        public int EntityType { get; private set; }
        /// <summary>
        /// 实体资源名
        /// </summary>
        public string EntityAsset { get; private set; }
        /// <summary>
        /// 死亡动画时长(毫秒)
        /// </summary>
        public int DieDuration { get; private set; }
        /// <summary>
        /// 英雄触发距离(cm)
        /// </summary>
        public int InteractExtendedRange { get; private set; }
        /// <summary>
        /// 实体默认速度(cm/s)
        /// </summary>
        public int DefaultSpeed { get; private set; }
        /// <summary>
        /// 实体转向时长(毫秒)
        /// </summary>
        public int RotationTime { get; private set; }
        /// <summary>
        /// 默认音频包
        /// </summary>
        public string DefaultAudioSheet { get; private set; }
        /// <summary>
        /// 是否播放激活动画
        /// </summary>
        public bool ActivateWallActionPlay { get; private set; }
        /// <summary>
        /// 是否不显示交互图标
        /// </summary>
        public bool NoInteractiveIcon { get; private set; }
        /// <summary>
        /// 范围触发行为(纯表现)
        /// </summary>
        public int ViewTriggerAction { get; private set; }
        /// <summary>
        /// 受击音效
        /// </summary>
        public int HitSound { get; private set; }


        /// <summary>
        /// post process table
        /// </summary>
        partial void PostInit();
    }

    /// <summary>
    /// internal common data.Optimize memory
    /// </summary>
    internal class _TbCommonPhysicalEntity
    {

        internal IReadOnlyList<string> _field0 { get; private set; }
        internal IReadOnlyList<string> _field1 { get; private set; }
        internal _TbCommonPhysicalEntity(ByteBuf _buf)
        {
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field0 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
            { int __n0 = _buf.ReadSize(); var __f0 = new string[__n0]; _field1 = __f0; for (var __i0 = 0 ; __i0 < __n0 ; __i0++ ){ string __v0; __v0 = _buf.ReadString(); __f0[__i0] = __v0;} }
        }

    }
}
